package se.perp.c4.model;

import java.io.Serializable;
import se.perp.c4.model.Territory.ETerritory;

public class Actor implements Serializable, Comparable<Actor> {

    public int compareTo(Actor o) {
        return name.compareTo(o.name);
    }

    public enum Side {

        DARK, LIGHT
    };

    public enum EActor {

        NOBODY,
        FRODO, SAM, MERRY, PIPPIN, GIMLI, LEGOLAS, ARAGORN, BOROMIR, GANDALF,
        CAVETROLL, ORCS, WARG, SARUMAN, SHELOB, BALROG, F_NAZGUL, B_RIDERS, WITCHKING
    };
    public static EActor[] LIGHT_ACTORS = {EActor.FRODO, EActor.SAM, EActor.MERRY, EActor.PIPPIN,
        EActor.GIMLI, EActor.LEGOLAS, EActor.BOROMIR, EActor.GANDALF, EActor.ARAGORN};
    public static EActor[] DARK_ACTORS = {EActor.CAVETROLL, EActor.ORCS, EActor.WARG, EActor.SARUMAN,
        EActor.SHELOB, EActor.BALROG, EActor.F_NAZGUL, EActor.B_RIDERS, EActor.WITCHKING};
    public String name;
    public String portraitName;
    public int attackValue;
    public String description;
    public Side side;
    public EActor who;
    public Territory.ETerritory where = ETerritory.NOWHERE;
    public boolean isAlive = true;

    public boolean isDark() {
        return side == Side.DARK;
    }

    public boolean isLight() {
        return side == Side.LIGHT;
    }

    public Side opposingSide() {
        if (side == Side.LIGHT) {
            return Side.DARK;
        }
        return Side.LIGHT;
    }

    @Override
    public String toString() {
        return who + "=" + name + ": isAlive=" + isAlive + ", where=" + where;
    }

    public static Side sideFor(EActor ea) {
        switch (ea) {
            case NOBODY:
                return null;
            case FRODO:
            case SAM:
            case MERRY:
            case PIPPIN:
            case LEGOLAS:
            case ARAGORN:
            case GIMLI:
            case GANDALF:
            case BOROMIR:
                return Side.LIGHT;
            default:
                return Side.DARK;
        }
    }

    public static boolean isDark(EActor ea) {
        return sideFor(ea) == Side.DARK;
    }

    public static boolean isLight(EActor ea) {
        return sideFor(ea) == Side.LIGHT;
    }

    public String isAre() {
        return Actor.isAre(who);
    }

    public static String isAre(EActor ea) {
        switch (ea) {
            case ORCS:
            case B_RIDERS:
                return "are";
            default:
                return "is";
        }
    }

    public static String retreats(EActor ea) {
        switch (ea) {
            case ORCS:
            case B_RIDERS:
                return "retreat";
            default:
                return "retreats";
        }
    }

    public static String isAre(Actor a) {
        return isAre(a.who);
    }
}
